package com.happyclub.lbjcontroller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 高欢
 * @description TODO
 * @date 2019/4/8
 */
@Controller
@RequestMapping("/weixin")
public class WeiXinShareController {
    @RequestMapping("/fuvk")
    public String testShare(){
        return "lbj-html/TestShareWeiXin";
    }

    @RequestMapping("/cc")
    public String testSendAct(){
        return "lbj-html/sendActivity";
    }

    @RequestMapping("/pro")
    public String testPro(){
        return "lbj-html/sendProduct";
    }
    /*@RequestMapping("/share")
    public void index(){
        // 微信appid
        String appid = "xxx";
        // 微信secret
        String secret = "xxx";
        // 初始化access_token
        String access_token = "";
        //  获取URL 这里的URL指的是需要分享的那个页面地址,建议这里不要写成固定地址，而是获取当前地址.
        String url = getPara("url");

        // 创建通过Api获取Token的链接与参数
        String requestTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET";
        requestTokenUrl = requestTokenUrl.replace("APPID", appid);
        requestTokenUrl = requestTokenUrl.replace("SECRET", secret);

        JSONObject jsonObjectToken = CommonUtil.httpsRequest(requestTokenUrl, "GET", null);
        if(StrKit.notNull(jsonObjectToken)){
            // 创建日期赋值为当前日期
            createDate = new Date().getTime()/1000;
            // 获取Token值
            access_token = jsonObjectToken.getString("access_token");
            // 获取Token有效期值
            expires_in = jsonObjectToken.getLong("expires_in");
        }

        String requestUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
        requestUrl = requestUrl.replace("ACCESS_TOKEN", access_token);
        // 获取凭证
        JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);
        if(StrKit.notNull(jsonObject)){
            try {
                String ticket = jsonObject.getString("ticket");
                String noncestr = WebUtils.getRandom(7);
                long timestamp = new Date().getTime()/1000;

                String param = "jsapi_ticket="+ticket+"&noncestr="+noncestr+"×tamp="+timestamp+"&url="+url;
                String signature = DigestUtils.shaHex(param);

                WeixinShare weixinShare = new WeixinShare();
                weixinShare.setWxNoncestr(noncestr);
                weixinShare.setWxTimestamp(timestamp);
                weixinShare.setWxSignature(signature);
                setAttr("weixinShare",weixinShare);
                setAttr("appid",appid);
            } catch (Exception e) {
                e.printStackTrace();
                setAttr("errorMessage","服务器异常！");
            }
        }
        renderJson();
    }*/
}
